<?php
namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Logic\UserLogic;

class UserController extends Controller
{
    
    function __construct(Request $request)
    {
            $this->request = $request;
    }
    
    
    /**
     * 用户管理页
     * 
     * @author 谢望鑫 <xiewxin@addcn.com>
     */
    public function userManage()
    {
        //$userModel=new User();
        
        //登录校验和管理员校验
//         $param['phone']=$phone;
//         $param['accesstoken']=$accesstoken;
//         $getToken=$userModel->getToken($param);
        
//         if (empty($getToken)){
//             abort(405, '请先登录~');
//         }else if($getToken->usertype!=1){//不是管理员
//             abort(405, '没有操作权限哟~');
//         }
        
        return view('user.userManage');
    }
    
    /**
     * 注册用户
     * 
     * @author 谢望鑫 <xiewxin@addcn.com>
     * 
     * @return JsonResponse
     */
    public function doRegister()
    {
      $param = $this->request->all();
      $userLogic = new UserLogic();
      $result = $userLogic->doRegister($param);
      
      return response()->json($result);
    }
    
    /**
     * 登录
     * 
     * @author 谢望鑫 <xiewxin@addcn.com>
     * 
     * @return JsonResponse
     */
    public function login()
    {
        $param = $this->request->all();
        $userLogic = new UserLogic();
        $result = $userLogic->login($param);
        
        return response()->json($result);
    }
   
    
    /**
     * 退出
     * 
     * @author 谢望鑫 <xiewxin@addcn.com>
     * 
     * @return JsonResponse
     */
    public function logout()
    {
        $param = $this->request->all();
        $userLogic = new UserLogic();
        $result = $userLogic->logout($param);
        
        return response()->json($result);
    }
    
    
    /**
     * 黑名单设置
     * 
     * @author 谢望鑫 <xiewxin@addcn.com>
     * 
     * @return JsonResponse
     */
    public function blacklistSetting()
    {
        $param = $this->request->all();
        $userLogic = new UserLogic();
        $result = $userLogic->blacklistSetting($param);
        
        return response()->json($result);
    }
      
    /**
     * 用户列表
     * 
     * @author 谢望鑫 <xiewxin@addcn.com>
     * 
     * @return JsonResponse
     */
    public function userList()
    {
        $param = $this->request->all();
        $userLogic = new UserLogic();
        $result=$userLogic->userList($param);
        
        return response()->json($result);
    }
    
    /**
     * 上传
     * 
     * @author 谢望鑫 <xiewxin@addcn.com>
     * 
     * @return JsonResponse
     */
    public function upload()
    {
        $request = $this->request;
        $userLogic = new UserLogic();
        $result = $userLogic->upload($request);
        
        return response()->json($result);
    }
    
}